﻿<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends Controller {

	var $meta_title;

	var $curr_page;

	var $cur_lang;

	function Page($lang=''){

		parent::Controller();	

		$this->meta_title 		= $this->config->item('default_meta_title');

		$this->meta_description = $this->config->item('default_meta_description');

		$this->meta_keywords	= $this->config->item('default_meta_keywords');

		$this->load->model('general_model');

		$this->html_title ="";$this->config->item('default_title_'.$this->lang->lang());

		if (empty($this->session->userdata['_visit'])){

			$this->session->userdata['_visit']=0;
		}

    }
	function _remap($method){		

		$layout 		= 'default';

		$template 		= 'main';

		$data 			= array();

		$cur_segment 	= $this->uri->segment(2);

		$sub_segment 	= $this->uri->segment(3);

		$detail_segment = $this->uri->segment(4);
		$last_segment = $this->uri->segment(5);

		$langcode=$this->lang->lang();

		switch ($cur_segment)

		{		
            case 'history' :
			case 'gecmisi' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_history');

					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/history.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/gecmisi.html";
					//$data['_activetab']="about_current";
					$template 			= 'history';

				break;
                
            case 'education' :
			case 'egitim' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_education');

					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/education.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/egitim.html";
					//$data['_activetab']="about_current";
					$template 			= 'education';

				break;
            case 'facilities' :
			case 'tesisler' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_facilities');

					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/facilities.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/tesisler.html";
					//$data['_activetab']="about_current";
					$data['tab']=$this->get_tabs($langcode,"facilities");
					$template 			= 'facilities';

				break;
            case 'events' :
			case 'olaylar' :

					//$data=$this->get_staticpage($langcode,3);
					$langcode=$this->lang->lang();
					$this->html_title 	= $this ->lang->line('fm_events');
					$data['currentlang']=($this->lang->lang()=='en')? base_url()."en":base_url()."tr";
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/events.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/olaylar.html";
					//$data['_activetab']="about_current";
					$eventlink=($this->lang->lang()=='tr')? "tr/olaydetay":"en/eventdetail";
					$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   =>  base_url().$langcode.'/loadcalendar/1/'
             );
        $prefs['template'] = '
        
        {table_open}<table border="0" cellspacing="0" cellpadding="0" id="calendartable" class="mc">{/table_open}

        {heading_row_start}<tr id="calendar_header"><th colspan="7"><div class="heading_calendar">
        
        <div class="float_left">

            <select id="month" class="events1_select">
                <option value="1" selected>January</option>
				<option value="2">February</option>
				<option value="3">March</option>
				<option value="4">April</option>
				<option value="5">May</option>
				<option value="6">June</option>
				<option value="7">July</option>
				<option value="8">August</option>
				<option value="9">September</option>
				<option value="10">October</option>
				<option value="11">November</option>
				<option value="12">December</option>
                
            </select>
            &nbsp;
            <select id="year" class="events2_select">
                <option value="2004">2004</option>
				<option value="2005">2005</option>
				<option value="2006">2006</option>
				<option value="2007">2007</option>
				<option value="2008">2008</option>
				<option value="2009">2009</option>
				<option value="2010">2010</option>
				<option value="2011" selected>2011</option>
				<option value="2012">2012</option>
				<option value="2013">2013</option>
				<option value="2014">2014</option>
				<option value="2015">2015</option>
				<option value="2016">2016</option>
				<option value="2017">2017</option>
				<option value="2018">2018</option>
				<option value="2019">2019</option>
				<option value="2020">2020</option>
                
            </select>
            &nbsp;
        </div>
        <div onclick="searchevent();" class="float_left p5t">
            <input  type="image" src="'.base_url().'assets/img/bt_go.jpg" style="vertical-align: middle;"/>
        </div>
        {/heading_row_start}

        {heading_previous_cell}<div class="float_left p38l"><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></div>{/heading_previous_cell}
        {heading_title_cell}<div class="float_left date_title"><p>{heading}</p></div>{/heading_title_cell}
        {heading_next_cell}<div class="float_left"><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Next"  title="Next" /></a></div>{/heading_next_cell}

        {heading_row_end}<div class="clear_left"></div></div></th></tr>{/heading_row_end}

        {week_row_start}<tr class="bg_day">{/week_row_start}
        {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
        {week_row_end}</tr>{/week_row_end}

        {cal_row_start}<tr>{/cal_row_start}
        {cal_cell_start}<td>{/cal_cell_start}
        
        {cal_cell_content}<div class="bg_evet_date1"><div class="autodiv">
            <p>
            {day}<br>
            {content}
            
            </p></div>
        </div>{/cal_cell_content}
        
        {cal_cell_content_today}<div class="bg_evet_date1">
            <p>
            <span style="color:red">{day}</span><br>
            {content}
            
            </p>
        </div>{/cal_cell_content_today}
        
        {cal_cell_no_content}<div class="autodiv"><p>&nbsp;{day}</p></div>{/cal_cell_no_content}
        {cal_cell_no_content_today}<div class="bg_curr_date1"><div class="autodiv"><p>{day}</p></div></div>{/cal_cell_no_content_today}
        
        {cal_cell_blank}<div class="none_date">&nbsp;</div>{/cal_cell_blank}
        
        {cal_cell_end}</td>{/cal_cell_end}
        {cal_row_end}</tr>{/cal_row_end}
        
        {table_close}</table>{/table_close}
        ';

		//$calendar2=$this->load->library('calendar2', $prefs);
		if($langcode=='en')
			{$this->load->library('calendar2', $prefs);}
		if($langcode=='tr')
			{$this->load->library('calendar3', $prefs);}
		// GET EVENTS =====================

		$local_time = time();
		$year  = date("Y", $local_time);
		$month = date("m", $local_time);
		$datetime = $month."-".$year;
		$days_arr = array(); // store events in this month
		$events = $this->general_model->get_events($langcode);
		if(count($events)>0)		
		{
			$numevent=1;
			$tempvalue='';
			$temp=0;
			foreach($events as $event)
			{
				$currentdate=date("d-m-Y",$event['e_date']);
					//echo $currentdate;
					$pos = strpos($currentdate,$datetime);// compare 05-2010   in  12-05-2010
					
					
					if($pos!='')
					{
						$evt = substr($currentdate,0,2); // get day number
						if($evt!=$temp)
						{
							
							$temp=$evt;						
							$days_arr[intval($evt)] = '» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
							$tempvalue='» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
						}
						else
						{
							$tempvalue.='» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
							$days_arr[intval($evt)]=$tempvalue;
						}
					}
					$numevent++;
			}
		}
        
		if (count($days_arr)>0)
		{
			 if($langcode=='en')
			 {$data['calendar'] = $this->calendar2->generate($this->uri->segment(3), $this->uri->segment(4),$days_arr);}
			 else
			 {$data['calendar'] = $this->calendar3->generate($this->uri->segment(3), $this->uri->segment(4),$days_arr);}
		}
		else
		{
			if($langcode=='en')
			{$data['calendar'] = $this->calendar2->generate();}
			if($langcode=='tr')
			{
				$data['calendar'] = $this->calendar3->generate();
			}
			

		}
		//=======================
					$template 			= 'events';

				break;
            case 'about' :
			case 'hakkinda' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_about');

					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/about.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/hakkinda.html";
					//$data['_activetab']="about_current";
					$data['tab']=$this->get_tabs($langcode,"about");
					$template 			= 'about';

				break;
			case 'contact' :
			case 'iletisim' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_contact');

					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/contact.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/iletisim.html";
					//$data['_activetab']="about_current";
					$template 			= 'contact';

				break;
            case 'publication' :
			case 'yayinlar' :

					//$data=$this->get_staticpage($langcode,3);

					$this->html_title 	= $this ->lang->line('fm_publication');
					$langcode=$this->lang->lang();
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/publication.html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/yayinlar.html";
					$data['tab']=$this->get_tabs($langcode,"publication");
					$template 			= 'publication';

				break;
			case 'workgroup' :
			case 'gruplari' :

					//$data=$this->get_staticpage($langcode,3);
					$opp_segment='';
					if($sub_segment=='education')
					{
						$opp_segment='egitim';
					}
					if($sub_segment=='publications')
					{
						$opp_segment='yayinlar';
					}
					if($sub_segment=='women')
					{
						$opp_segment='kadin';
					}
					if($sub_segment=='music')
					{
						$opp_segment='muzik';
					}
					if($sub_segment=='youth')
					{
						$opp_segment='genclik';
					}
					if($sub_segment=='sport')
					{
						$opp_segment='spor';
					}
					
					
					if($sub_segment=='egitim')
					{
						$opp_segment='education';
					}
					if($sub_segment=='yayinlar')
					{
						$opp_segment='publications';
					}
					if($sub_segment=='kadin')
					{
						$opp_segment='women';
					}
					if($sub_segment=='muzik')
					{
						$opp_segment='music';
					}
					if($sub_segment=='genclik')
					{
						$opp_segment='youth';
					}
					if($sub_segment=='spor')
					{
						$opp_segment='sport';
					}

					$this->html_title 	= $this ->lang->line('fm_workgroup');
					$langcode=$this->lang->lang();
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/workgroup/".$opp_segment.".html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/gruplari/".$opp_segment.".html";
					$data['tab']=$this->get_tabs($langcode,$opp_segment);
					$template 			= 'workgroup';

				break;	
            case 'newsdetail':
            case 'haberdetay':
                    	//$data=$this->get_staticpage($langcode,3);
					$id=$this->uri->segment(3);
					$this->html_title 	= $this ->lang->line('fm_newss');
					$langcode=$this->lang->lang();
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/newsdetail/".$id.".html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/haberdetay/".$id.".html";
					//$data['_activetab']="about_current";
					
					$data['news']=$this->get_newsdetail($langcode,$id);
					$template 			= 'newsdetail';

				break;
            case 'eventdetail':
            case 'olaydetay':
                    	//$data=$this->get_staticpage($langcode,3);
					$id=$this->uri->segment(3);
					$this->html_title 	= $this ->lang->line('fm_events');
					$langcode=$this->lang->lang();
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/eventdetail/".$id.".html";

					$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/olaydetay/".$id.".html";
					//$data['_activetab']="about_current";
					
					$data['news']=$this->get_eventdetail($langcode,$id);
					$data['gallery']=$this->get_gallerydetail($id);
					$template 			= 'eventdetail';

				break;

			case 'news_send':
					
                    //print_r($_POST);
                    
                    
                    $data = array(
					   'email' => $_POST['news_email'] ,
					   'name' => $_POST['news_name'] ,
					   'date' => time()
					);
					
					$this->db->insert('subscribers', $data); 
                    $this->session->set_flashdata('message', '<div style="color:red">'.$this->lang->line('msg_subscribing').'</div>');
                     redirect('/');
			
					break;

            case 'education_send':
					
                   
                    $mylink=($this->lang->lang()=='en')? base_url()."en/education.html":base_url()."tr/egitim.html";
					$data = array(
					   'email' => $_POST['email'] ,
					   'name' => $_POST['name'] ,
					   'message' => $_POST['message'] ,
					   'phone' => $_POST['phone'] ,
					   'childname' => $_POST['childname'] ,
					   'childage' => $_POST['childage']
					);
					
					$this->db->insert('registration', $data); 
                    $this->session->set_flashdata('message', '<div style="color:red">'.$this->lang->line('msg_register').'</div>');
					redirect($mylink);
			
			break;
            case 'facilities_send':
					
                   
                     $mylink=($this->lang->lang()=='en')? base_url()."en/facilities.html":base_url()."tr/tesisler.html";
					$data = array(
					   'email' => $_POST['email'] ,
					   'name' => $_POST['name'] ,
					   'phone' => $_POST['phone'] ,
					    'date' => time()
					);
					
					$this->db->insert('booking', $data); 
                    $this->session->set_flashdata('message', '<div style="color:red">'.$this->lang->line('msg_booking').'</div>');
					redirect($mylink);
			
			break;
		
			case 'news' :

			case 'haber' :

				$this->html_title 	= $this ->lang->line('fm_newss');
                $langcode=$this->lang->lang();
				$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/news.html";

				$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/haber.html";				
                
                $data['news']=$this->get_total_news($langcode);
                
				$template 			= 'news';

				break;

			case 'getfile' :

				$this->load->helper('download');
				$filename=$sub_segment;
				$thefile=$_SERVER["DOCUMENT_ROOT"].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME'])."/upload_file/download/".$filename;
				if (file_exists($thefile)) 
				{
					$data = file_get_contents($thefile); // Read the file's contents
		
					force_download($filename, $data); 
					die;
				}
				else
				{
					redirect("/");	
				}
				
				break;
				
           	case 'downloads' :

			case 'yuklemeler' :

				$this->html_title 	= $this ->lang->line('fm_downloads');
                $langcode=$this->lang->lang();
				$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en/downloads.html";

				$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr/yuklemeler.html";				
                
                //$data['news']=$this->get_total_news($langcode);
				$data['tab']=$this->get_category($langcode);
				$data['list1']=$this->get_downloadlist($langcode,10);
				$data['list2']=$this->get_downloadlist($langcode,11);
				$data['list3']=$this->get_downloadlist($langcode,12);				
                
				$template 			= 'downloads';

				break;

            case 'send' :

			case 'send' :

                $name = $this->input->post('name', true);
                $phone = $this->input->post('phone', true);
                $email = $this->input->post('email', true);
                $message = $this->input->post('message', true);
                
				$this->html_title 	= $this ->lang->line('fm_message');
                $langcode=$this->lang->lang();
				
                $data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en";

				$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr";				
                //Send mail contact
                $this->mail_progress($name, $phone, $email, $message);
                
				$template 			= 'message';

				break;


			case 'search' :

			case 'arama' :

					$keyword=xss_clean($this->input->post('searchtxt'),$charset = 'UTF-8');
					//echo $keyword;
					//die;
					$langcode=$this->lang->lang();
					$data['news']=$this->listsearch_result('news',$langcode,$keyword);
					//var_dump($data['news']);
					$data['events']=$this->listsearch_result('event',$langcode,$keyword);
					/*$data['currenturl']=($langcode=='vn')?base_url().$langcode."/san-pham/":base_url().$langcode."/product/";
					$data['list_product']=$this->get_searchlistproduct($langcode,$keyword);
					//var_dump($data['list_product']);
					//exit;*/
					$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en";

				$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr";
					$this->html_title 	= $this ->lang->line('fm_home');

					$data['currentlang']=($this->lang->lang()=='en')? base_url()."en/search/":base_url()."tr/arama/";
			
					$data['currentlang_event']=($this->lang->lang()=='tr')? base_url()."tr/olaydetay/":base_url()."en/eventdetail/";

					$data['currentlang_news']=($this->lang->lang()=='tr')? base_url()."tr/haberdetay/":base_url()."en/newsdetail/";

					$this->html_title 	=($langcode=='en')?"Search result":"Arama sonucu";

					$data['keywordtemp']=$keyword;
					$template 			= 'search';

				break;
				case 'loadcalendar' :
$type=1;
$m=$last_segment;
$i=$detail_segment;
//echo $m."/".$i;
					if(!(int)$type){
			return;
		}
		$langcode=$this->lang->lang();
$eventlink=($this->lang->lang()=='tr')? "tr/olaydetay":"en/eventdetail";
		$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   =>  base_url().$langcode.'/loadcalendar/'.$type.'/'
             );
		if($type==2){
		  
            $prefs['template'] = '
            
            {table_open}<table border="0" cellspacing="0" cellpadding="0" class="mc">{/table_open}
            
            {heading_row_start}<tr id="calendar_header">{/heading_row_start}
            {heading_previous_cell}<th><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></th>{/heading_previous_cell}
            {heading_title_cell}<th colspan="{colspan}"><h2>{heading}</h2></th>{/heading_title_cell}
            {heading_next_cell}<th><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Next"  title="Next" /></a></th>{/heading_next_cell}
            {heading_row_end}</tr>{/heading_row_end}
            
            {week_row_start}<tr class="bg_day">{/week_row_start}
            {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}
            
            {cal_row_start}<tr>{/cal_row_start}
            {cal_cell_start}<td class="w14p">{/cal_cell_start}
            
            {cal_cell_content}<div class="bg_evet_date"><a style="color:white" href="{content}" title="View information about this event">{day}</a></div>{/cal_cell_content}
            {cal_cell_content_today}<div class="bg_evet_date"><a style="color:white" href="{content}">{day}</a></div>{/cal_cell_content_today}
            
            {cal_cell_no_content}<p>{day}</p>{/cal_cell_no_content}
            {cal_cell_no_content_today}<div class="bg_curr_date">{day}</div>{/cal_cell_no_content_today}
            
            {cal_cell_blank}{/cal_cell_blank}
            
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}
            
            {table_close}</table>{/table_close}
            ';
            $this->load->library('calendar', $prefs);
	
			// GET EVENTS =====================
            
			$datetime = $m."-".$i;
			$days_arr=array(); // store events in this month
			$events = $this->general_model->get_events($langcode);
			if(count($events)>0)		
			{
				foreach($events as $event)
				{
					$currentdate=date("d-m-Y",$event['e_date']);
					//echo $currentdate;
					$pos = strpos($currentdate,$datetime);// compare 05-2010   in  12-05-2010
					if($pos!='')
					{
						$evt = substr($currentdate,0,2); // get day number
						$days_arr[intval($evt)] = base_url().$eventlink."/".$event['id'].".html";
					}
				}
			}
			if (count($days_arr)>0)
			{
				 echo $this->calendar->generate($i,$m,$days_arr);
			}
			else
			{
				echo $this->calendar->generate($i,$m);
	
			}
		}
		else
		{
                    $prefs['template'] = '
        
        {table_open}<table border="0" cellspacing="0" cellpadding="0" id="calendartable" class="mc">{/table_open}

        {heading_row_start}<tr id="calendar_header"><th colspan="7"><div class="heading_calendar">
        
        <div class="float_left">

            <select id="month" class="events1_select">
                <option value="1" selected>January</option>
				<option value="2">February</option>
				<option value="3">March</option>
				<option value="4">April</option>
				<option value="5">May</option>
				<option value="6">June</option>
				<option value="7">July</option>
				<option value="8">August</option>
				<option value="9">September</option>
				<option value="10">October</option>
				<option value="11">November</option>
				<option value="12">December</option>
                
            </select>
            &nbsp;
            <select id="year" class="events2_select">
			 <option value="2004">2004</option>
				<option value="2005">2005</option>
				<option value="2006">2006</option>
				<option value="2007">2007</option>
				<option value="2008">2008</option>
				<option value="2009">2009</option>
                <option value="2010">2010</option>
				<option value="2011" selected>2011</option>
				<option value="2012">2012</option>
				<option value="2013">2013</option>
				<option value="2014">2014</option>
				<option value="2015">2015</option>
				<option value="2016">2016</option>
				<option value="2017">2017</option>
				<option value="2018">2018</option>
				<option value="2019">2019</option>
				<option value="2020">2020</option>
                
            </select>
            &nbsp;
        </div>
        <div onclick="searchevent();" class="float_left p5t">
            <input  type="image" src="'.base_url().'assets/img/bt_go.jpg" style="vertical-align: middle;"/>
        </div>
        {/heading_row_start}

        {heading_previous_cell}<div class="float_left p38l"><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></div>{/heading_previous_cell}
        {heading_title_cell}<div class="float_left date_title"><p>{heading}</p></div>{/heading_title_cell}
        {heading_next_cell}<div class="float_left"><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Next"  title="Next" /></a></div>{/heading_next_cell}

        {heading_row_end}<div class="clear_left"></div></div></th></tr>{/heading_row_end}

        {week_row_start}<tr class="bg_day">{/week_row_start}
        {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
        {week_row_end}</tr>{/week_row_end}

                {cal_row_start}<tr>{/cal_row_start}
        {cal_cell_start}<td>{/cal_cell_start}
        
        {cal_cell_content}<div class="bg_evet_date1"><div class="autodiv">
            <p>
            {day}<br>
            {content}
            
            </p></div>
        </div>{/cal_cell_content}
        
        {cal_cell_content_today}<div class="bg_evet_date1">
            <p>
            <span style="color:red">{day}</span><br>
            {content}
            
            </p>
        </div>{/cal_cell_content_today}
        
        {cal_cell_no_content}<div class="autodiv"><p>&nbsp;{day}</p></div>{/cal_cell_no_content}
        {cal_cell_no_content_today}<div class="bg_curr_date1"><p>{day}</p></div>{/cal_cell_no_content_today}
        
        {cal_cell_blank}<div class="none_date">&nbsp;</div>{/cal_cell_blank}
        
        {cal_cell_end}</td>{/cal_cell_end}
        {cal_row_end}</tr>{/cal_row_end}
        
        {table_close}</table>{/table_close}
        ';
			if($langcode=='en'){
			$this->load->library('calendar2', $prefs);}
			else
			{$this->load->library('calendar3', $prefs);}
			// GET EVENTS =====================
			$datetime = $m."-".$i; // month-years
			$days_arr = array(); // store events in this month
			$events = $this->general_model->get_events($langcode);
			if(count($events)>0)		
			{
				$numevent=1;
			$tempvalue='';
			$temp=0;
			foreach($events as $event)
			{
				$currentdate=date("d-m-Y",$event['e_date']);
					//echo $currentdate;
					$pos = strpos($currentdate,$datetime);// compare 05-2010   in  12-05-2010
					
					
					if($pos!='')
					{
						$evt = substr($currentdate,0,2); // get day number
						if($evt!=$temp)
						{
							
							$temp=$evt;						
							$days_arr[intval($evt)] = '» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
							$tempvalue='» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
						}
						else
						{
							$tempvalue.='» <a href="'.base_url().$eventlink."/".$event['id'].".html".'" title="View information about this event">'.$event['name'].'</a><br />';
							$days_arr[intval($evt)]=$tempvalue;
						}
					}
					$numevent++;
			}
			}
			if (count($days_arr)>0)
			{
				 if($langcode=='en'){
				 echo $this->calendar2->generate($i,$m,$days_arr);}
				 else
				 {echo $this->calendar3->generate($i,$m,$days_arr);}
			}
			else
			{
				if($langcode=='en')
				{echo $this->calendar2->generate($i,$m);}
				else
				{echo $this->calendar3->generate($i,$m);}
			}
		
		die;
		}

				break;				


			default :	
				//$data=$this->main($langcode);
				
				$this->html_title 	= $this ->lang->line('fm_home');

				$data['changlang_en']=($this->lang->lang()=='en')? "#":base_url()."en";

				$data['changlang_tr']=($this->lang->lang()=='tr')? "#":base_url()."tr";
				
                $template 			= 'main';
                
                $data['banners']=$this->get_banners($langcode);
				$data['news']=$this->get_2latestnews($langcode);
				$data['tab']=$this->get_tabs($langcode,"homemanager");
                break;

		}

		$this->_render($data, $template, $layout,$langcode);

	}

	function _render($_data, $template, $layout,$langcode){
	   
        $data = array();
        $_data['title'] 	= $this->html_title;
        
        //$data['wiki_prelink']=($this->lang->lang()=='vn')? base_url()."vn/tim-hieu-cac-loai-hat":base_url()."en/nuts-wiki";
        
        
        
        //$data['testimonial']=$this->footer(2,$this->lang->lang());
		$data['seach_url']=($this->lang->lang()=='en')? base_url()."en/search/":base_url()."tr/arama/";
        
        $data['main'] 		= $this->load->view('subpage/'.$template, $_data, true);
        $this->load->view($layout, $data);
	}
	function calendar(){
        $prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   =>  base_url().'loadkalendar/2/'
             );
        $prefs['template'] = '
        
        {table_open}<table border="0" cellspacing="0" cellpadding="0" class="mc">{/table_open}
        
        {heading_row_start}<tr id="calendar_header">{/heading_row_start}
        {heading_previous_cell}<th><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></th>{/heading_previous_cell}
        {heading_title_cell}<th colspan="{colspan}"><h2 class="green_text">{heading}</h2></th>{/heading_title_cell}
        {heading_next_cell}<th><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Next"  title="Next" /></a></th>{/heading_next_cell}
        {heading_row_end}</tr>{/heading_row_end}
        
        {week_row_start}<tr class="bg_day">{/week_row_start}
        {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
        {week_row_end}</tr>{/week_row_end}
        
        {cal_row_start}<tr>{/cal_row_start}
        {cal_cell_start}<td class="w14p">{/cal_cell_start}
        
        {cal_cell_content}<div class="bg_evet_date"><a href="{content}" title="See information about this event">{day}</a></div>{/cal_cell_content}
        {cal_cell_content_today}<div class="bg_evet_date"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
        
        {cal_cell_no_content}<p>{day}</p>{/cal_cell_no_content}
        {cal_cell_no_content_today}<div class="bg_curr_date">{day}</div>{/cal_cell_no_content_today}
        
        {cal_cell_blank}{/cal_cell_blank}
        
        {cal_cell_end}</td>{/cal_cell_end}
        {cal_row_end}</tr>{/cal_row_end}
        
        {table_close}</table>{/table_close}
        ';

		$this->load->library('calendar2', $prefs);
		// GET EVENTS =====================

		$local_time = time();
		$year  = date("Y", $local_time);
		$month = date("m", $local_time);
		$datetime = $month."-".$year;
		$days_arr = array(); // store events in this month
		$events = $this->general_model->get_events($langcode);
		if(count($events)>0)		
		{
			foreach($events as $event)
			{
				$pos = strpos($event['e_date'],$datetime);// compare 05-2010   in  12-05-2010
				if($pos!='')
				{
					$evt = substr($event['e_date'],0,2); // get day number
					$days_arr[intval($evt)] = base_url()."events/".$event['id'].".html";
				}
			}
		}
        
		if (count($days_arr)>0)
		{
			 $data['calendar'] = $this->calendar2->generate($this->uri->segment(3), $this->uri->segment(4),$days_arr);
		}
		else
		{
			$data['calendar'] = $this->calendar2->generate();

		}
		//=======================
		
		$data['title']='Calendar';
		$data['content']='calendar';
		$this->load->view('templates',$data,'');
	}
    function loadkalendar($type,$i,$m){
        
	    if(!(int)$type){
			return;
		}
		$langcode=$this->lang->lang();
		$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   =>  base_url().$langcode.'/loadkalendar/'.$type.'/'
             );
		if($type==1){
		  
            $prefs['template'] = '
            
            {table_open}<table border="0" cellspacing="0" cellpadding="0" class="mc">{/table_open}
            
            {heading_row_start}<tr id="calendar_header">{/heading_row_start}
            {heading_previous_cell}<th><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></th>{/heading_previous_cell}
            {heading_title_cell}<th colspan="{colspan}"><h2>{heading}</h2></th>{/heading_title_cell}
            {heading_next_cell}<th><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Next"  title="Next" /></a></th>{/heading_next_cell}
            {heading_row_end}</tr>{/heading_row_end}
            
            {week_row_start}<tr class="bg_day">{/week_row_start}
            {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}
            
            {cal_row_start}<tr>{/cal_row_start}
            {cal_cell_start}<td class="w14p">{/cal_cell_start}
            
            {cal_cell_content}<div class="bg_evet_date"><a href="{content}" title="See information about this event">{day}</a></div>{/cal_cell_content}
            {cal_cell_content_today}<div class="bg_evet_date"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
            
            {cal_cell_no_content}<p>{day}</p>{/cal_cell_no_content}
            {cal_cell_no_content_today}<div class="bg_curr_date">{day}</div>{/cal_cell_no_content_today}
            
            {cal_cell_blank}{/cal_cell_blank}
            
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}
            
            {table_close}</table>{/table_close}
            ';
            $this->load->library('calendar', $prefs);
	
			// GET EVENTS =====================
            
			$datetime = $m."-".$i;
			$days_arr=array(); // store events in this month
			$events = $this->general_model->get_events($langcode);
			if(count($events)>0)		
			{
				foreach($events as $event)
				{
					$pos = strpos($event['e_date'],$datetime);// compare 05-2010   in  12-05-2010
					if($pos!='')
					{
						$evt = substr($event['e_date'],0,2); // get day number
						$days_arr[intval($evt)] = base_url()."events/".$event['id'].".html";
					}
				}
			}
			if (count($days_arr)>0)
			{
				 echo $this->calendar->generate($i,$m,$days_arr);
			}
			else
			{
				echo $this->calendar->generate($i,$m);
	
			}
		}
		else{
            $prefs['template'] = '
            
            {table_open}<table border="0" cellspacing="0" cellpadding="0" class="mc">{/table_open}
            
            {heading_row_start}<tr id="calendar_header">{/heading_row_start}
            {heading_previous_cell}<th><a href="{previous_url}"><img src="'.base_url().'assets/img/pre_but.png" alt="Preview" title="Preview" /></a></th>{/heading_previous_cell}
            {heading_title_cell}<th colspan="{colspan}"><h2 class="green_text">{heading}</h2></th>{/heading_title_cell}
            {heading_next_cell}<th><a href="{next_url}"><img src="'.base_url().'assets/img/next_but.png" alt="Næste"  title="Næste" /></a></th>{/heading_next_cell}
            {heading_row_end}</tr>{/heading_row_end}
            
            {week_row_start}<tr class="bg_day">{/week_row_start}
            {week_day_cell} <th><p>{week_day}</p></th>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}
            
            {cal_row_start}<tr>{/cal_row_start}
            {cal_cell_start}<td class="w14p">{/cal_cell_start}
            
            {cal_cell_content}<div class="bg_evet_date"><a href="{content}" title="See information about this event">{day}</a></div>{/cal_cell_content}
            {cal_cell_content_today}<div class="bg_evet_date"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
            
            {cal_cell_no_content}<p>{day}</p>{/cal_cell_no_content}
            {cal_cell_no_content_today}<div class="bg_curr_date">{day}</div>{/cal_cell_no_content_today}
            
            {cal_cell_blank}{/cal_cell_blank}
            
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}
            
            {table_close}</table>{/table_close}
            ';

			$this->load->library('calendar2', $prefs);
			// GET EVENTS =====================
			$datetime = $m."-".$i; // month-years
			$days_arr = array(); // store events in this month
			$events = $this->general_model->get_events($langcode);
			if(count($events)>0)		
			{
				foreach($events as $event)
				{
					$pos = strpos($event['e_date'],$datetime);// compare 05-2010   in  12-05-2010
					if($pos!='')
					{
						$evt=substr($event['e_date'],0,2); // get day number
						$days_arr[intval($evt)] = base_url()."events/".$event['id'].".html";
					}
				}
			}
			if (count($days_arr)>0)
			{
				 echo $this->calendar2->generate($i,$m,$days_arr);
			}
			else
			{
				echo $this->calendar2->generate($i,$m);
	
			}
		}
	}
	function footer($langcode)

	{
			$result_footers=$this->general_model->get_testimonial_footer($langcode);
	
			if($result_footers->num_rows()>0)
	
			{
					$footer= $result_footers->result_array();
			}
			return $footer;

	}
	
    //// SEND MAIL ////
    function mail_progress($name, $phone, $email, $message)
	{
		$this->load->library('email');
		$this->email->from($email, $name);
		
        $this->email->to('info@ideabox.com.au');
		//$this->email->cc('duccuong0205@gmail.com');
		
		$this->email->subject('Contact from Western Thrace Website');
		$this->email->message($message);
		
		$this->email->send();
		
        return true;
	}
    
    function server_parse($socket, $response)
    {
       $server_response = '';
       while ( substr($server_response,3,1) != ' ' )
       {
          if( !( $server_response = fgets($socket, 256) ) )
          {
             echo "Couldn't get mail server response codes";
          }
       }
    
       if( !( substr($server_response, 0, 3) == $response ) )
       {
          //echo " Error on mailserver";
       }
    }
    function smtpmail($mail_to, $subject, $message, $headers='',$smtp_host, $smtp_username, $smtp_password, 

    $admin_email)
    {
    //global $smtp_host, $smtp_username, $smtp_password, $admin_email;
    //echo $to_mail.$subject.$message.$headers.$smtp_host.$smtp_username.$smtp_password;
    
            //
            // Fix any bare linefeeds in the message to make it RFC821 Compliant.
            //
            $message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
       /*echo "SMTP_HOST".$smtp_host;
       echo "<br>\nSMTP_USER".$smtp_user;
       echo "<br>\nSMTP_PW".$smtp_password;
       echo "<br>\nADMIN".$admin_email; */
    
            if ($headers != "")
            {
                    if(is_array($headers))
                    {
                            if(sizeof($headers) > 1)
                            {
                                    $headers = join("\r\n", $headers);
                            }
                            else
                            {
                                    $headers = $headers[0];
                            }
                    }
                    $headers = chop($headers);
    
                    //
                    // Make sure there are no bare linefeeds in the headers
                    //
                    $headers = preg_replace("/(?<!\r)\n/si", "\r\n", $headers);
                    //
                    // Ok this is rather confusing all things considered,
                    // but we have to grab bcc and cc headers and treat them differently
                    // Something we really didn't take into consideration originally
                    //
                    $header_array = explode("\r\n", $headers);
                    @reset($header_array);
                    $headers = "";
                    $cc = '';
                    $bcc = '';
                    while( list(, $header) = each($header_array) )
                    {
                            if( preg_match("/^cc:/si", $header) )
                            {
                                    $cc = preg_replace("/^cc:(.*)/si", "\\1", $header);
                            }
                            else if( preg_match("/^bcc:/si", $header ))
                            {
                                    $bcc = preg_replace("/^bcc:(.*)/si", "\\1", $header);
                                    $header = "";
                            }
                            $headers .= $header . "\r\n";
                    }
                    $headers = chop($headers);
                    $cc = explode(",", $cc);
                    $bcc = explode(",", $bcc);
            }
    
    
            if(trim($mail_to) == "")
            {
                    exit();
            }
            if(trim($subject) == "")
            {
                    die("No email Subject specified");
            }
    
            $mail_to_array = explode(",", $mail_to);
    
            //
            // Ok we have error checked as much as we can to this point let's get on
            // it already.
            //
            if( !$socket = fsockopen($smtp_host, 25, $errno, $errstr, 20) )
            {
                    die("Could not connect to smtp host : $errno : $errstr");
            }
            $this->server_parse($socket, "220");
    
            if( !empty($smtp_username) && !empty($smtp_password) )
            {
                    // Send the RFC2554 specified EHLO.
                    // This improved as provided by SirSir to accomodate
                    // both SMTP AND ESMTP capable servers
                    fputs($socket, "EHLO " . $smtp_host . "\r\n");
                    $this->server_parse($socket, "250");
    
                    fputs($socket, "AUTH LOGIN\r\n");
                    $this->server_parse($socket, "334");
                    fputs($socket, base64_encode($smtp_username) . "\r\n");
                    $this->server_parse($socket, "334");
                    fputs($socket, base64_encode($smtp_password) . "\r\n");
                    $this->server_parse($socket, "235");
            }
            else
            {
                    // Send the RFC821 specified HELO.
                    fputs($socket, "HELO " . $smtp_host . "\r\n");
                    $this->server_parse($socket, "250");
            }
    
            // From this point onward most server response codes should be 250
            // Specify who the mail is from....
            fputs($socket, "MAIL FROM: <" . $admin_email . ">\r\n");
            $this->server_parse($socket, "250");
    
            // Specify each user to send to and build to header.
            $to_header = "To: ";
            @reset( $mail_to_array );
            while( list( , $mail_to_address ) = each( $mail_to_array ))
            {
                    //
                    // Add an additional bit of error checking to the To field.
                    //
                    $mail_to_address = trim($mail_to_address);
                    if ( preg_match('/[^ ]+\@[^ ]+/', $mail_to_address) )
                    {
                            fputs( $socket, "RCPT TO: <$mail_to_address>\r\n" );
                            $this->server_parse( $socket, "250" );
                    }
                    $to_header .= "<$mail_to_address>, ";
            }
            // Ok now do the CC and BCC fields...
            @reset( $bcc );
            while( list( , $bcc_address ) = each( $bcc ))
            {
                    //
                    // Add an additional bit of error checking to bcc header...
                    //
                    $bcc_address = trim( $bcc_address );
                    if ( preg_match('/[^ ]+\@[^ ]+/', $bcc_address) )
                    {
                            fputs( $socket, "RCPT TO: <$bcc_address>\r\n" );
                            $this->server_parse( $socket, "250" );
                    }
            }
            @reset( $cc );
            while( list( , $cc_address ) = each( $cc ))
            {
                    //
                    // Add an additional bit of error checking to cc header
                    //
                    $cc_address = trim( $cc_address );
                    if ( preg_match('/[^ ]+\@[^ ]+/', $cc_address) )
                    {
                            fputs($socket, "RCPT TO: <$cc_address>\r\n");
                            $this->server_parse($socket, "250");
                    }
            }
            // Ok now we tell the server we are ready to start sending data
            fputs($socket, "DATA\r\n");
    
            // This is the last response code we look for until the end of the message.
            $this->server_parse($socket, "354");
    
            // Send the Subject Line...
            fputs($socket, "Subject: $subject\r\n");
    
            // Now the To Header.
            fputs($socket, "$to_header\r\n");
    
            // Now any custom headers....
            fputs($socket, "$headers\r\n\r\n");
    
            // Ok now we are ready for the message...
            fputs($socket, "$message\r\n");
    
            // Ok the all the ingredients are mixed in let's cook this puppy...
            fputs($socket, ".\r\n");
            $this->server_parse($socket, "250");
    
            // Now tell the server we are done and close the socket...
            fputs($socket, "QUIT\r\n");
            fclose($socket);
    
            return TRUE;
    }
    function SendMail($frommail,$tomail,$subject,$message,$fromfullname="hatviet.com")
    {
          $from= $fromfullname." <".$frommail.">";
          $headers ="Return-Path: ".$fromfullname." <".$frommail.">\r\n";
          $headers.="From: $from\nX-Mailer: ".$fromfullname."\r\n";
          $headers .="Mime-Version: 1.0\r\n";
          $headers .="Content-type: text/html; charset=utf-8\r\n";
          $smtp_host ='mail.3nc.com.vn';//mail server
          $admin_email = 'test@3nc.com.vn';
          $smtp_username = 'test@3nc.com.vn';
          $smtp_password = '11111';
          $result = $this->smtpmail($tomail,$subject,$message,$headers,$smtp_host, $smtp_username, $smtp_password, $admin_email);
    
    }


	function get_banners($langcode)
	{
		$result_list_product=$this->general_model->get_banners($langcode);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
    function get_category($langcode)
	{
		$result_list_product=$this->general_model->get_category($langcode);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	function get_downloadlist($langcode,$category)
	{
		$result_list_product=$this->general_model->get_downloadlist($langcode,$category);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
    function get_total_news($langcode)
	{
		$get_total_news=$this->general_model->get_total_news($langcode);
		$news=array();
		if($get_total_news->num_rows()>0)
		{
			$news=$get_total_news->result_array();
		}

		return $news;
	}
	
	function get_2latestnews($langcode)
	{
		$result_list_product=$this->general_model->get_2latestnews($langcode);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	function get_newsdetail($langcode,$id)
	{
		$result_list_product=$this->general_model->get_newsdetail($langcode,$id);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	function get_eventdetail($langcode,$id)
	{
		$result_list_product=$this->general_model->get_eventdetail($langcode,$id);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	
	function get_gallerydetail($id)
	{
		$result_list_product=$this->general_model->get_gallerydetail($id);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	
	function get_tabs($langcode,$tab)
	{
		$result_list_product=$this->general_model->get_tabs($langcode,$tab);
		$banners=array();
		if($result_list_product->num_rows()>0)

		{

			$banners=$result_list_product->result_array();
		}

		return $banners;
	}
	function main($langcode)

	{

		$result_hot_news=$this->general_model->get_hot_news($langcode);

		if($result_hot_news->num_rows()>0)

		{

			$i=0;

			foreach ($result_hot_news->result() as $row)

			{

				$hot_news[$i]= array(

					   '0'  => $row->title_alias,

					   '1'   => $row->small_img,

					   '2'  => $row->title,

					   '3'  => $row->small_info,					   


					);

					$i++;

			}

		}

		$data['hot_news']=$hot_news;
		
		$result_random_products=$this->general_model->get_information_page($langcode,4);

		if($result_random_products->num_rows()>0)

		{
			foreach ($result_random_products->result() as $row)
			{

				$random_products[0]= array(

					   '0'  => $row->description
					);


			}

		}

		$data['sales']=$random_products;		
		$data['slideshows']=$this->footer($this->lang->lang());
		return $data;		

	}

	function listsearch_result($type,$langcode,$keyword)

	{

			$result_listsearch=$this->general_model->get_listsearch_result($type,$langcode,$keyword);

			if($result_listsearch->num_rows()>0)
			{
					$listsearch=$result_listsearch->result_array();

			}
			else
			{
				$listsearch= array();	
			}

		$data=$listsearch;
		return $data;
	}	
}



/* End of file welcome.php */

/* Location: ./system/application/controllers/welcome.php */